package com.pengtu.gsj.service.impl.lwfw;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.dao.lwfw.EmergRepairDao;
import com.pengtu.gsj.entity.app.Attachment;
import com.pengtu.gsj.entity.lwfw.EmergRepair;
import com.pengtu.gsj.service.lwfw.EmergRepairService;
import com.pengtu.gsj.service.system.SystemManageService;

@Service
@Transactional
public class EmergRepairServiceImpl implements EmergRepairService{
	
	@Autowired
	private EmergRepairDao emergRepairDao;
	@Autowired
	private SystemManageService systemManageService;
	
	@Override
	public void saveEmergRepair(EmergRepair emergRepair){
		emergRepairDao.save(emergRepair);
	}
	
	@Override
	public Page<EmergRepair> findEmergRepair(Page<EmergRepair> page, final QueryFilter queryFilter){
		return emergRepairDao.findPage(page, queryFilter);
	}
	
	@Override
	public EmergRepair getEmergRepairById(String id){
		return emergRepairDao.get(id);
	}
	
	@Override
	public void  delateEmergRepair(EmergRepair emergRepair){
		if(emergRepair.getAttachments() != null){
			for(Attachment attachment : emergRepair.getAttachments()){
				systemManageService.deleteAttachment(attachment);
			}
		}
		emergRepairDao.delete(emergRepair);
	}

	/**
	 * 
	 * checkYear:
	 * 适用:判断年份信息是否已经存在
	 * @param year 用户填写的年份信息
	 * @param id 对应项目id
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@Override
	public boolean checkYear(String year, String id) {
		return emergRepairDao.checkProperty("year", year, id);
	}
}
